package cn.iocoder.yudao.module.product.controller.admin.calculation;

import cn.iocoder.yudao.module.product.controller.admin.calculation.vo.ProcessCalculationCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.calculation.vo.ProcessCalculationRespVO;
import cn.iocoder.yudao.module.product.controller.admin.calculation.vo.ProcessCalculationUpdateReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.module.product.dal.dataobject.calculation.ProcessCalculationDO;
import cn.iocoder.yudao.module.product.convert.calculation.ProcessCalculationConvert;
import cn.iocoder.yudao.module.product.service.calculation.ProcessCalculationService;

@Tag(name =  "管理后台 - 工序-核算关联")
@RestController
@RequestMapping("/product/process-calculation")
@Validated
public class ProcessCalculationController {

    @Resource
    private ProcessCalculationService processCalculationService;

    @PostMapping("/create")
    @Operation(summary = "创建工序-核算关联")
    @PreAuthorize("@ss.hasPermission('product:process-calculation:create')")
    public CommonResult<Long> createProcessCalculation(@Valid @RequestBody ProcessCalculationCreateReqVO createReqVO) {
        return success(processCalculationService.createProcessCalculation(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新工序-核算关联")
    @PreAuthorize("@ss.hasPermission('product:process-calculation:update')")
    public CommonResult<Boolean> updateProcessCalculation(@Valid @RequestBody ProcessCalculationUpdateReqVO updateReqVO) {
        processCalculationService.updateProcessCalculation(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除工序-核算关联")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('product:process-calculation:delete')")
    public CommonResult<Boolean> deleteProcessCalculation(@RequestParam("id") Long id) {
        processCalculationService.deleteProcessCalculation(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得工序-核算关联")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('product:process-calculation:query')")
    public CommonResult<ProcessCalculationRespVO> getProcessCalculation(@RequestParam("id") Long id) {
        ProcessCalculationDO processCalculation = processCalculationService.getProcessCalculation(id);
        return success(ProcessCalculationConvert.INSTANCE.convert(processCalculation));
    }

}
